//
//  HMHomeToolBar.swift
//  Weibo
//
//  Created by fuyu on 2017/7/26.
//  Copyright © 2017年 itteacher. All rights reserved.
//

import UIKit
import SnapKit

class HMHomeToolBar: UIView {

    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }



//添加控件约束
private func setupUI() {
    let retweetButton = addChildButton(imageName: "timeline_icon_retweet", title: "转发")
    let commnetButton = addChildButton(imageName: "timeline_icon_comment", title: "评论")
    let unlikeButton = addChildButton(imageName: "timeline_icon_unlike", title: "赞")
    
    //添加约束
    retweetButton.snp.makeConstraints { (make) in
        make.top.leading.bottom.equalTo(self)
        make.width.equalTo(commnetButton)
    }
    commnetButton.snp.makeConstraints { (make) in
        make.top.bottom.equalTo(self)
        make.leading.equalTo(retweetButton.snp.trailing)
        make.width.equalTo(unlikeButton)
    }
    unlikeButton.snp.makeConstraints { (make) in
        make.top.trailing.bottom.equalTo(self)
        //  关键约束
        make.leading.equalTo(commnetButton.snp.trailing)
    }
    
    //第一条线
    let firstLineView = addLineView()
    
    //第二条线
    let secondLineView = addLineView()
    
    //  添加约束
    firstLineView.snp.makeConstraints { (make) in
        make.centerX.equalTo(retweetButton.snp.trailing)
        make.centerY.equalTo(retweetButton)
    }
    secondLineView.snp.makeConstraints { (make) in
        make.centerX.equalTo(commnetButton.snp.trailing)
        make.centerY.equalTo(commnetButton)
    }

    
}

//添加子按钮
private func addChildButton(imageName: String, title: String) -> UIButton {
    
    let button = UIButton()
    
    //图片
    button.setImage(UIImage(named: imageName), for: .normal)
    //背景图片
    button.setBackgroundImage(UIImage(named: "timeline_card_bottom_background"), for: .normal)
    //设置文字
    button.setTitle(title, for: .normal)
    button.titleLabel?.font = UIFont.systemFont(ofSize: 14)
    button.setTitleColor(UIColor.darkGray, for: .normal)
    button.adjustsImageWhenHighlighted = false
    
    //添加
    addSubview(button)
    return button
    }
    
    //添加竖线视图
    private func addLineView() -> UIImageView {
        
        let imageView = UIImageView(image:UIImage(named: "timeline_card_bottom_line"))
        //添加子视图
        addSubview(imageView)
        return imageView
        
    }
    
}


